home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap09 / howto06 / delphi10 / cciccinf.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-12  |  11.5 KB  |  347 lines

  1. unit Cciccinf;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Grids, Outline, CCWSock;
  8.  
  9. type
  10.   TCCICInfoDlg = class(TForm)
  11.     Panel1: TPanel;
  12.     BitBtn1: TBitBtn;
  13.     BitBtn2: TBitBtn;
  14.     Panel4: TPanel;
  15.     ListBox2: TListBox;
  16.     Panel2: TPanel;
  17.     Edit1: TEdit;
  18.     Panel3: TPanel;
  19.     Edit2: TEdit;
  20.     Panel5: TPanel;
  21.     Edit3: TEdit;
  22.     Panel8: TPanel;
  23.     Edit4: TEdit;
  24.     Panel9: TPanel;
  25.     Edit5: TEdit;
  26.     Panel6: TPanel;
  27.     Outline1: TOutline;
  28.     Label1: TLabel;
  29.     Label2: TLabel;
  30.     Button1: TButton;
  31.     Button2: TButton;
  32.     Button3: TButton;
  33.     Button4: TButton;
  34.     procedure Button1Click(Sender: TObject);
  35.     procedure ListBox2Click(Sender: TObject);
  36.     procedure BitBtn1Click(Sender: TObject);
  37.     procedure BitBtn2Click(Sender: TObject);
  38.     procedure Edit4Exit(Sender: TObject);
  39.     procedure Button2Click(Sender: TObject);
  40.     procedure Button3Click(Sender: TObject);
  41.     procedure Button4Click(Sender: TObject);
  42.   private
  43.     { Private declarations }
  44.   public
  45.     { Public declarations }
  46.   end;
  47.  
  48. var
  49.   CCICInfoDlg: TCCICInfoDlg;
  50.  
  51. implementation
  52.  
  53. uses CCICCFrm;
  54.  
  55. function inet_addr( IPAddressName : PChar ) :
  56.           Unsigned_Long_Integer; far; external 'WINSOCK';
  57. function gethostbyname( TheName : PChar ) :
  58.           PHost_Entry; far; external 'WINSOCK';
  59.  
  60. {$R *.DFM}
  61. procedure TCCICInfoDlg.Button1Click(Sender: TObject);
  62. var TempSocket : TCCSocket; { Used for IP Address info }
  63.     DataBuffer : array[ 0 .. 256 ] of char;
  64. begin
  65.   case Tag of
  66.     1 : begin  { Get IP Address Mode }
  67.           { Create the dummy socket }
  68.           TempSocket := TCCSocket.Create( Self );
  69.           TempSocket.Parent := Self;
  70.           { Use it to get the info }
  71.           with TempSocket do
  72.           begin
  73.             { Move the IP address into the data buffer }
  74.             StrPCopy( DataBuffer , Edit1.Text );
  75.             { Turn it into a real IP address in binary form }
  76.             Socket_IP_Address.Socket_Address.Full_Internet_Address :=
  77.              inet_addr( DataBuffer );
  78.             { If not found then do remote lookup }
  79.             if Socket_IP_Address.Socket_Address.Full_Internet_Address = INADDR_NONE then
  80.             begin
  81.               { Call blocking function on IP name }
  82.               Socket_Host_Entry := gethostbyname( DataBuffer );
  83.               { If still no good then error out and exit }
  84.               if Socket_Host_Entry = nil then
  85.               begin
  86.                 Edit2.Text := 'Could Not Convert Host Name';
  87.                 Edit3.Text := '';
  88.               end
  89.               else
  90.               begin
  91.                 { Otherwise get the address }
  92.                 Socket_IP_Address.Socket_Address :=
  93.                  Socket_Host_Entry^.Host_Address^^;
  94.                 Edit2.Text :=
  95.                  IntToStr( Socket_IP_Address.Socket_Address.Net_Byte ) + '.' +
  96.                  IntToStr( Socket_IP_Address.Socket_Address.Host_Byte ) + '.' +
  97.                  IntToStr( Socket_IP_Address.Socket_Address.Local_Host_Byte ) +
  98.                  '.' + IntToStr(
  99.                  Socket_IP_Address.Socket_Address.Local_Machine_Byte );
  100.                 Edit3.Text :=
  101.                  IntToStr( Socket_IP_Address.Socket_Address.
  102.                             Full_Internet_Address );
  103.               end;
  104.             end;
  105.           end;
  106.           { Free the dummy socket }
  107.           TempSocket.Free;
  108.         end;
  109.     2 : begin { Anonymous login punch }
  110.           Edit3.Text := 'anonymous';
  111.           CurrentRealPWString := CurrentPassWordString;
  112.           case PasswordControlVector of
  113.             1 : Edit4.Text := CurrentPassWordString;
  114.             2 : Edit4.Text := '**********';
  115.           end;
  116.         end;
  117.   end;
  118. end;
  119.  
  120. procedure TCCICInfoDlg.ListBox2Click(Sender: TObject);
  121. begin
  122.   { Use Tag vector to find out how to interpret a click }
  123.   case Tag of
  124.     2 : begin
  125.           { If nothing in list box then exit }
  126.           if ListBox2.ItemIndex = -1 then exit;
  127.           { Use the data in the Working FTP Site List TList }
  128.           with PConnectionsRecord(
  129.            TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  130.           begin
  131.               Edit1.Text := CProfile;
  132.               Edit2.Text := CIPAddress;
  133.               Edit3.Text := CUserName;
  134.               CurrentRealPWString := CPassword;
  135.               case PasswordControlVector of
  136.                 1 : Edit4.Text := CPassword;
  137.                 2 : Edit4.Text := '**********';
  138.               end;
  139.               Edit5.Text := CStartDir;
  140.           end;
  141.         end;
  142.   end;
  143. end;
  144.  
  145. { This procedure saves the newly modified list of stuff to its base }
  146. procedure TCCICInfoDlg.BitBtn1Click(Sender: TObject);
  147. var Counter_1  : SmallInt;            { Loop counter        }
  148.     ThePointer : PConnectionsRecord; { Generic TCR Pointer }
  149. begin
  150.   { Use the tag vector to find out what to do }
  151.   case Tag of
  152.     2 : begin { Do FTP Site List }
  153.           { dispose the old FTP site list's pointers }
  154.           for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  155.           begin
  156.             Dispose( PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] ));
  157.           end;
  158.           { Clear the lists }
  159.           TheFTPSiteList.Clear;
  160.           CCInetCCForm.ComboBox1.Clear;
  161.           { Add the new info }
  162.           for Counter_1 := 0 to TheWorkingFTPSL.Count - 1 do
  163.           begin
  164.             { Create a new pointer }
  165.             New( ThePointer );
  166.             { Move the data into it }
  167.             ThePointer^ :=
  168.              PConnectionsRecord( TheWorkingFTPSL.Items[ Counter_1 ] )^;
  169.             { Add the item }
  170.             TheFTPSiteList.Add( ThePointer );
  171.             CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  172.              TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  173.           end;
  174.           CCINetCCForm.ComboBox1.ItemIndex := 0;
  175.         end;
  176.   end;
  177.   { Leave }
  178.   Close;
  179. end;
  180.  
  181. { This method cancels any changes made from entries in current setup & exits}
  182. procedure TCCICInfoDlg.BitBtn2Click(Sender: TObject);
  183. var Counter_1  : SmallInt;            { Loop counter        }
  184.     ThePointer : PConnectionsRecord; { Generic TCR Pointer }
  185. begin
  186.   { Use Tag vector do decide what to reset }
  187.   case Tag of
  188.     2 : begin { Reset FTP Site list }
  189.           { Dispose of all the old pointers }
  190.           for Counter_1 := 0 to TheWorkingFTPSL.Count - 1 do
  191.           begin
  192.             Dispose( PConnectionsRecord( TheWorkingFTPSL.Items[ Counter_1 ] ));
  193.           end;
  194.           { Clear the working list }
  195.           TheWorkingFTPSL.Clear;
  196.           { Clear the listbox }
  197.           ListBox2.Clear;
  198.           { Then rebuild the working list and display listbox }
  199.           for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  200.           begin
  201.             { Create the record }
  202.             New( ThePointer );
  203.             { Move data in }
  204.             ThePointer^ :=
  205.              PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] )^;
  206.             { Add the pointer to the list }
  207.             TheWorkingFTPSL.Add( ThePointer );
  208.             { Add the profile name to the list }
  209.             ListBox2.Items.Add( PConnectionsRecord(
  210.              TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  211.           end;
  212.         end;
  213.   end;
  214.   { Leave }
  215.   Close;
  216. end;
  217.  
  218. procedure TCCICInfoDlg.Edit4Exit(Sender: TObject);
  219. begin
  220.   { Use tag vector to determine action }
  221.   case Tag of
  222.     2 : begin
  223.           { If Edit4 is modified then mangle pw }
  224.           if Edit4.Modified then
  225.           begin
  226.             { Save pw in either case, but mangle if masked }
  227.             case PasswordControlVector of
  228.               1 : CurrentRealPWString := Edit4.Text;
  229.               2 : begin
  230.                     CurrentRealPWString := Edit4.Text;
  231.                     Edit4.Text := '***********';
  232.                   end;
  233.             end;
  234.           end;
  235.         end;
  236.   end;
  237. end;
  238.  
  239. { Add button; do various add actions }
  240. procedure TCCICInfoDlg.Button2Click(Sender: TObject);
  241. var ThePointer : PConnectionsRecord; { PCR Pointer }
  242. begin
  243.   { Tag vector control as usual }
  244.   case Tag of
  245.     2 : begin { add new FTP site list entry }
  246.           { Creat new PCR pointer }
  247.           New( ThePointer );
  248.           { Add in the data from the text fields }
  249.           with ThePointer^ do
  250.           begin
  251.             CProfile   := Edit1.Text;
  252.             CIPAddress := Edit2.Text;;
  253.             CUserName  := Edit3.Text;
  254.             { Put in the real pw string }
  255.             CPassword  := CurrentRealPWString;
  256.             CStartDir  := Edit5.Text;
  257.           end;
  258.           { Add pointer to working list }
  259.           TheWorkingFTPSL.Add( ThePointer );
  260.           { Add it to the listbox }
  261.           ListBox2.Items.Add( ThePointer^.CProfile );
  262.           { And set the pointer to it }
  263.           ListBox2.ItemIndex := ListBox2.Items.Count - 1;
  264.         end;
  265.   end;
  266. end;
  267.  
  268. { This is the modify button }
  269. procedure TCCICInfoDlg.Button3Click(Sender: TObject);
  270. begin
  271.   { Use Tag vector as usual }
  272.   case Tag of
  273.     2 : begin
  274.           { if nothing to modify the exit }
  275.           if ListBox2.ItemIndex = -1 then exit;
  276.           { get record of current listbox pointer & put in data }
  277.           with PConnectionsRecord(
  278.            TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  279.           begin
  280.             CProfile   := Edit1.Text;
  281.             CIPAddress := Edit2.Text;;
  282.             CUserName  := Edit3.Text;
  283.             { Put in the real pw string }
  284.             CPassword  := CurrentRealPWString;
  285.             CStartDir  := Edit5.Text;
  286.           end;
  287.           { Make sure the display matches the edit control }
  288.           ListBox2.Items[ ListBox2.ItemIndex ] := Edit1.Text;
  289.         end;
  290.   end;
  291. end;
  292.  
  293. { This is the delete button }
  294. procedure TCCICInfoDlg.Button4Click(Sender: TObject);
  295. var MessageString : string; { string holder }
  296. begin
  297.   { Use tag control vector }
  298.   case Tag of
  299.     2 : begin
  300.           { If nothing to delete then leave }
  301.           if Listbox2.Itemindex = -1 then exit;
  302.           { Set up display }
  303.           MessageString := 'Delete Entry ' + Edit1.Text + '?';
  304.           { Display message box and get result }
  305.           if MessageDlg( MessageString , mtConfirmation , mbYesNoCancel , 0 )
  306.            = mrYes then
  307.           begin
  308.             { if ok delete then remove item from working sl }
  309.             TheWorkingFTPSL.Delete( ListBox2.ItemIndex );
  310.             { delete from listbox }
  311.             ListBox2.Items.Delete( ListBox2.ItemIndex );
  312.             { If nothing left set itemindex and clear edits }
  313.             if ListBox2.Items.Count = 0 then
  314.             begin
  315.               ListBox2.ItemIndex := -1;
  316.               Edit1.Text := '';
  317.               Edit2.Text := '';
  318.               Edit3.Text := '';
  319.               Edit4.Text := '';
  320.               Edit5.Text := '';
  321.             end
  322.             else
  323.             begin
  324.               { Reset listbox pointer }
  325.               ListBox2.ItemIndex  := 0;
  326.               { and reset display to new item }
  327.               with PConnectionsRecord(
  328.                TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  329.               begin
  330.                 Edit1.Text := CProfile;
  331.                 Edit2.Text := CIPAddress;
  332.                 Edit3.Text := CUserName;
  333.                 CurrentRealPWString := CPassword;
  334.                 case PasswordControlVector of
  335.                   1 : Edit4.Text := CPassword;
  336.                   2 : Edit4.Text := '**********';
  337.                 end;
  338.                 Edit5.Text := CStartDir;
  339.               end;
  340.             end;
  341.           end;
  342.         end;
  343.   end;
  344. end;
  345.  
  346. end.
  347.